package com.zhentao.controller;

import com.zhentao.dto.FilesDto;
import com.zhentao.files.TbFiles;
import com.zhentao.files.param.FilesParam;
import com.zhentao.service.TbChannelService;
import com.zhentao.service.TbFilesService;
import com.zhentao.service.TbWarehouseService;
import com.zhentao.utils.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/files")
@Slf4j
public class FilesController {
    @Autowired
    TbFilesService tbFilesService;
    @Autowired
    TbChannelService tbChannelService;
    @Autowired
    TbWarehouseService tbWarehouseService;

    /**
     * @param file
     * @return com.zhentao.utils.ResponseResult
     * @description 读图文文件
     * @author 振涛教育_小Q
     * @date 2024/12/7 21:41
     */
    @PostMapping("/upload")
    public ResponseResult uploadImage(@RequestBody MultipartFile file) {
        log.info("文件已经执行完毕");
        return tbFilesService.uploadImage(file);
    }

    /**
     * @param param
     * @return com.zhentao.utils.ResponseResult
     * @description 上传档案
     * @author 振涛教育_小Q
     * @date 2024/12/7 21:41
     */
    @PostMapping("/uploadFiles")
    public ResponseResult uploadFiles(@RequestBody FilesParam param) {
        return tbFilesService.uploadFiles(param);
    }

    /**
     * 用户查询档案
     *
     * @param
     * @return ResponseResult
     */
    @PostMapping("/select")
    public ResponseResult select(@RequestBody FilesDto fileDto) {
        return tbFilesService.select(fileDto);
    }

    /**
     * 用户修改档案
     *
     * @param
     * @return tbFiles
     */
    @PostMapping("/update")
    public ResponseResult updateFile(@RequestBody TbFiles tbFiles) {
        return tbFilesService.updateFile(tbFiles);
    }

    /**
     * 用户上架
     *
     * @param
     * @return tbFiles
     */
    @PostMapping("/shang")
    public ResponseResult shang(Long id) {
        return tbFilesService.shang(id);
    }

    /**
     * 用户下架
     *
     * @param
     * @return tbFiles
     */
    @PostMapping("/xia")
    public ResponseResult xiajia(Long id) {
        return tbFilesService.xiajiaa(id);
    }

    /**
     * 查询一下仓库
     *
     * @param
     * @return tbFiles
     */
    @PostMapping("/cang")
    public ResponseResult cangk() {
        return tbWarehouseService.cangku();
    }

    /**
     * 用户逻辑删除
     *
     * @param
     * @return tbFiles
     */
    @PostMapping("/shanchu")
    public ResponseResult delectt(@Param("id") Integer id) {
        return tbFilesService.shanchur(id);
    }

    //    用戶公開檔案
    @PostMapping("/dangan")
    public ResponseResult danganan(@RequestBody FilesDto fileDto) {
        return tbFilesService.gongkai(fileDto);
    }

    @PostMapping("/updateBy")
    public ResponseResult updateById(TbFiles tbFiles){
        return ResponseResult.okResult(tbFilesService.updateById(tbFiles));
    }

}
